home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / mail / pine3.96.tar.gz / pine3.96.tar / pine3.96 / imap / ANSI / c-client / env_mac.c < prev    next >
C/C++ Source or Header  |  1995-08-10  |  6KB  |  201 lines

  1. /*
  2.  * Program:    Mac environment routines
  3.  *
  4.  * Author:    Mark Crispin
  5.  *        6158 Lariat Loop NE
  6.  *        Bainbridge Island, WA  98110-2098
  7.  *        Internet: MRC@Panda.COM
  8.  *
  9.  * Date:    26 January 1992
  10.  * Last Edited:    10 August 1995
  11.  *
  12.  * Copyright 1995 by Mark Crispin
  13.  *
  14.  *  Permission to use, copy, modify, and distribute this software and its
  15.  * documentation for any purpose and without fee is hereby granted, provided
  16.  * that the above copyright notice appears in all copies and that both the
  17.  * above copyright notices and this permission notice appear in supporting
  18.  * documentation, and that the name of Mark Crispin not be used in advertising
  19.  * or publicity pertaining to distribution of the software without specific,
  20.  * written prior permission.  This software is made available "as is", and
  21.  * MARK CRISPIN DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD TO
  22.  * THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED WARRANTIES OF
  23.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN NO EVENT SHALL
  24.  * MARK CRISPIN BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
  25.  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  26.  * WHETHER IN AN ACTION OF CONTRACT, TORT (INCLUDING NEGLIGENCE) OR STRICT
  27.  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
  28.  * THIS SOFTWARE.
  29.  *
  30.  */
  31.  
  32.  
  33. static char *myLocalHost = NIL;    /* local host name */
  34. static char *myNewsrc = NIL;    /* newsrc file name */
  35.  
  36. /* Environment manipulate parameters
  37.  * Accepts: function code
  38.  *        function-dependent value
  39.  * Returns: function-dependent return value
  40.  */
  41.  
  42. void *env_parameters (long function,void *value)
  43. {
  44.   switch ((int) function) {
  45.   case SET_LOCALHOST:
  46.     myLocalHost = cpystr ((char *) value);
  47.     break;
  48.   case GET_LOCALHOST:
  49.     value = (void *) myLocalHost ? myLocalHost : "random-mac";
  50.     break;
  51.   case SET_NEWSRC:
  52.     if (myNewsrc) fs_give ((void **) &myNewsrc);
  53.     myNewsrc = cpystr ((char *) value);
  54.     break;
  55.   case GET_NEWSRC:
  56.                 /* set news file name if not defined */
  57.     if (!myNewsrc) myNewsrc = cpystr (".newsrc");
  58.     value = (void *) myNewsrc;
  59.     break;
  60.   default:
  61.     value = NIL;        /* error case */
  62.     break;
  63.   }
  64.   return value;
  65. }
  66.  
  67. /* Write current time
  68.  * Accepts: destination string
  69.  *        format of date and time
  70.  *
  71.  * This depends upon the ReadLocation() call in System 7 and the
  72.  * user properly setting his location/timezone in the Map control
  73.  * panel.
  74.  * Nothing is done about the gmtFlags.dlsDelta byte yet, since I
  75.  * don't know how it's supposed to work.
  76.  */
  77.  
  78. /* PPC cretins broke the MachineLocation struct */
  79.  
  80. #define gmtFlags u
  81.  
  82. static void do_date (char *date,char *fmt)
  83. {
  84.   long tz,tzm;
  85.   time_t ti = time (0);
  86.   struct tm *t = localtime (&ti);
  87.   MachineLocation loc;
  88.   ReadLocation (&loc);        /* get location/timezone poop */
  89.                 /* get sign-extended time zone */
  90.   tz = (loc.gmtFlags.gmtDelta & 0x00ffffff) |
  91.     ((loc.gmtFlags.gmtDelta & 0x00800000) ? 0xff000000 : 0);
  92.   tz /= 60;            /* get timezone in minutes */
  93.   tzm = tz % 60;        /* get minutes from the hour */
  94.                 /* output time */
  95.   strftime (date,MAILTMPLEN,fmt,t);
  96.                 /* now output time zone */
  97.   sprintf (date += strlen (date),"%+03ld%02ld",tz/60,tzm >= 0 ? tzm : -tzm);
  98. }
  99.  
  100.  
  101. /* Write current time in RFC 822 format
  102.  * Accepts: destination string
  103.  */
  104.  
  105. void rfc822_date (char *date)
  106. {
  107.   do_date (date,"%a, %d %b %Y %H:%M:%S ");
  108. }
  109.  
  110.  
  111. /* Write current time in internal format
  112.  * Accepts: destination string
  113.  */
  114.  
  115. void internal_date (char *date)
  116. {
  117.   do_date (date,"%2d-%b-%Y %H:%M:%S ");
  118. }
  119.  
  120. /* Determine default prototype stream to user
  121.  * Returns: default prototype stream
  122.  */
  123.  
  124. MAILSTREAM *default_proto ()
  125. {
  126.   extern MAILSTREAM dummyproto;
  127.   return &dummyproto;        /* return default driver's prototype */
  128. }
  129.  
  130.  
  131. /* Return my local host name
  132.  * Returns: my local host name
  133.  */
  134.  
  135. char *mylocalhost (void)
  136. {
  137.   return (char *) mail_parameters (NIL,GET_LOCALHOST,NIL);
  138. }
  139.  
  140. /* Block until event satisfied
  141.  * Called as: while (wait_condition && wait ());
  142.  * Returns T if OK, NIL if user wants to abort
  143.  *
  144.  * Allows user to run a desk accessory, select a different window, or go
  145.  * to another application while waiting for the event to finish.  COMMAND/.
  146.  * will abort the wait.
  147.  * Assumes the Apple menu has the apple character as its first character,
  148.  * and that the main program has disabled all other menus.
  149.  */
  150.  
  151. long wait ()
  152. {
  153.   EventRecord event;
  154.   WindowPtr window;
  155.   MenuInfo **m;
  156.   long r;
  157.   Str255 tmp;
  158.                 /* wait for an event */
  159.   WaitNextEvent (everyEvent,&event,(long) 6,NIL);
  160.   switch (event.what) {        /* got one -- what is it? */
  161.   case mouseDown:        /* mouse clicked */
  162.     switch (FindWindow (event.where,&window)) {
  163.     case inMenuBar:        /* menu bar item? */
  164.                 /* yes, interesting event? */    
  165.       if (r = MenuSelect (event.where)) {
  166.                 /* round-about test for Apple menu */
  167.       if ((*(m = GetMHandle (HiWord (r))))->menuData[1] == appleMark) {
  168.                 /* get desk accessory name */ 
  169.       GetItem (m,LoWord (r),tmp);
  170.       OpenDeskAcc (tmp);    /* fire it up */
  171.       SetPort (window);    /* put us back at our window */
  172.     }
  173.     else SysBeep (60);    /* the fool forgot to disable it! */
  174.       }
  175.       HiliteMenu (0);        /* unhighlight it */
  176.       break;
  177.     case inContent:        /* some window was selected */
  178.       if (window != FrontWindow ()) SelectWindow (window);
  179.       break;
  180.     default:            /* ignore all others */
  181.       break;
  182.     }
  183.     break;
  184.   case keyDown:            /* key hit - if COMMAND/. then punt */
  185.     if ((event.modifiers & cmdKey) && (event.message & charCodeMask) == '.')
  186.       return NIL;
  187.     break;
  188.   default:            /* ignore all others */
  189.     break;
  190.   }
  191.   return T;            /* try wait test again */
  192. }
  193.  
  194. /* Return random number
  195.  */
  196.  
  197. long random ()
  198. {
  199.   return (long) rand () << 16 + rand ();
  200. }
  201.